﻿
@using IOA.MES.DataAccess.Enum
@{
    ViewBag.Title = "标片管理";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
}

<div id="page"></div>

<script type="text/template" id="tplPage">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">{{lang.Field.StandardTabletCode}}：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtCode" placeholder="请输入标片条码" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">{{lang.Field.StandardTabletStatus}}：</label>
                        <div class="layui-input-inline">
                            <select id="selStatus" lay-filter="selStatus">
                                <option value="-1">所有状态</option>
                                <option value="@((int)CommonStatus.Normal)" selected>正常</option>
                                <option value="@((int)CommonStatus.Disabled)">禁用</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="btnSearch" class="layui-btn layuiadmin-btn-list" type="button">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                        <button class="layui-btn layui-btn-normal layuiadmin-btn-list" type="button" onclick="editPiece(0);">
                            <i class="layui-icon layui-icon-addition layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-card">
            <div class="layui-card-body">
                <table id="table" lay-filter="table"></table>
            </div>
        </div>
    </div>
</script>

@section Scripts{
    <script>
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package
            }
        });

        setTimeout(function () {
            initLayui();
        }, 50);
        function initLayui() {
            layui.use(['table', 'layer', 'laydate', 'form'], function () {
                var layer = layui.layer,
                    table = layui.table,
                    laydate = layui.laydate,
                    form = layui.form;

                var options = {
                    elem: '#table'
                    , url: '/ParaSetting/QueryStandardPieces'
                    , method: "post"
                    , where: { status: 1, code: '' }
                    , page: {
                        limit: 15
                        , limits: [15, 20, 25, 30, 40, 50]
                    }
                    , response: {
                        statusName: 'ErrCode'
                        , statusCode: 200
                        , msgName: 'ErrCode'
                        , countName: 'TotalCount'
                        , dataName: 'Data'
                    }
                    , cols: [[
                        { title: '序号', type: "numbers", width: 60, fixed: "left" }
                        , { field: 'Model', title: '型号', minWidth: 180 }
                        , { field: 'ProductCode', title: '条码', minWidth: 200 }
                        , {
                            title: 'Pmax', minWidth: 180, templet: function (d) {
                                return d.Pmax + "(" + d.PmaxToleranceDown + "-" + d.PmaxToleranceUp + ")";
                            }
                        }
                        , {
                            title: 'Voc', minWidth: 180, templet: function (d) {
                                return d.Voc + "(" + d.VocToleranceDown + "-" + d.VocToleranceUp + ")";
                            }
                        }
                        , {
                            title: 'Isc', minWidth: 180, templet: function (d) {
                                return d.Isc + "(" + d.IscToleranceDown + "-" + d.IscToleranceUp + ")";
                            }
                        }
                        , {
                            title: 'Vmp', minWidth: 180, templet: function (d) {
                                return d.Vmp + "(" + d.VmpToleranceDown + "-" + d.VmpToleranceUp + ")";
                            }
                        }
                        , {
                            title: 'Imp', minWidth: 180, templet: function (d) {
                                return d.Imp + "(" + d.ImpToleranceDown + "-" + d.ImpToleranceUp + ")";
                            }
                        }
                        , {
                            title: 'FF', minWidth: 180, templet: function (d) {
                                return d.FF + "(" + d.FFToleranceDown + "-" + d.FFToleranceUp + ")";
                            }
                        }
                        , { field: 'CNStatus', minWidth: 80, title: '状态' }
                        , { field: 'CreateTimeStr', minWidth: 180, title: '创建时间' }
                        , {
                            title: '操作', width: 180, fixed: "right", templet: function (d) {
                                var str = '<button class="layui-btn layui-btn-sm layui-btn-normal" onclick="editPiece(' + d.PkId + ')"><i class="layui-icon">&#xe642;</i>编辑</button>\
                                                                   <button class="layui-btn layui-btn-sm" onclick="modifyStatus(' + d.PkId + ',' + (1 - d.Status) + ')"><i class="layui-icon">&#xe616;</i>' + (d.Status == 0 ? "启用" : "禁用") + '</button>';
                                return str;
                            }
                        }
                    ]]
                };

                $("#btnSearch").click(function () {
                    queryTable();
                });
                queryTable();
                function queryTable() {
                    options.page.curr = 1;
                    var status = parseInt($("#selStatus").val().trim()),
                        productCode = $("#txtCode").val().trim();
                    options.where.status = status == "-1" ? null : parseInt(status);
                    options.where.code = productCode;

                    if (table.index <= 0) {
                        table.render(options);
                    } else {
                        table.reload("table", options);
                    }
                }
            });
        }

        function editPiece(pieceId) {
            layer.open({
                type: 2,
                shade: [0.1, '#000'],
                area: ['550px', '500px'],
                content: "/ParaSetting/EditStandardPiece?pieceId=" + pieceId,
                end: function () {
                    $("#btnSearch").click();
                }
            });
        }

        function modifyStatus(pieceId, status) {
            var loadId = layer.load();
            $.ajax({
                url: "/ParaSetting/ModifyStandardPieceStatus",
                data: {
                    pieceId: pieceId,
                    status: status
                },
                complete: function () {
                    layer.close(loadId);
                },
                success: function (res) {
                    if (res.ErrCode != 200) {
                        layer.msg(res.ErrMsg, { icon: 5 });
                        return;
                    }
                    layer.msg("修改成功！", { icon: 6, time: 1500 });
                    $("#btnSearch").click();
                }
            });
        }
    </script>
}
